package cn.edu.njuit.children.apis;

import cn.edu.njuit.children.common.Result;
import cn.edu.njuit.children.entity.Encyclopedia;
import cn.edu.njuit.children.entity.Menu;
import cn.edu.njuit.children.mapper.EncyclopediaMapper;
import cn.edu.njuit.children.mapper.MenuMapper;
import cn.edu.njuit.children.service.EncyclopediaService;
import cn.edu.njuit.children.service.MenuService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: TODO
 * @Data: 2022/11/29 15:31
 * @Author: guzy
 */
@RestController
@RequestMapping("/api/menu")
@Api(value = "菜谱接口", tags = "菜谱接口")
public class MenuApis {
    @Autowired
    MenuService service;
    @Autowired
    MenuMapper mapper;


    @PostMapping
    public Result save(@RequestBody Menu o) {
        return Result.success(service.save(o));
    }

    @PutMapping
    public Result update(@RequestBody Menu o) {
        return Result.success(service.updateById(o));
    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable Integer id) {
        return Result.success(service.removeById(id));
    }

    @GetMapping("{id}")
    public Result getById(@PathVariable Integer id) {
        return Result.success(service.getById(id));
    }

    @GetMapping("{currentPage}/{pageSize}")
    public Result getPage(@PathVariable Integer currentPage, @PathVariable int pageSize) {
        IPage<Menu> page = new Page<Menu>(currentPage,pageSize);
        mapper.selectPage(page, null);
        return Result.success(page);
    }
}
